import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;


public class LocalDateTimeDemo {
    public static void main(String[] args) {
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);
        LocalDateTime ldt1 = LocalDateTime.of(2022,5,16,16,29,28);
        System.out.println(ldt1);

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SS");
        //format(TemporalAccessor temporal) TemporalAccessor:接口
        //TemporalAccessor的子接口Temporal
        //LocalDateTime是Temporal的实现类
        //LocalDateTime同样也是TemporalAccessor的实现类
        //调用format()需要TemporalAccessor的对象，所需只需要传入LocalDateTime的对象
        //多态
        String str = dtf.format(ldt);
        System.out.println(str);

        System.out.println(ldt.format(dtf));
        //年
        System.out.println(ldt.getYear());
        //月 月份对应数值，月份对应Month的对象
        System.out.println(ldt.getMonthValue());
        Month month = ldt.getMonth();
        //5 -- MAY
        System.out.println(month.getValue());

        //获取天数
        System.out.println(ldt.getDayOfMonth());
        //星期
        DayOfWeek dow = ldt.getDayOfWeek();
        System.out.println(dow.getValue());

        DayOfWeek dow1 = DayOfWeek.of(7);
        System.out.println(dow1);
        //这一天在这一年的第几天
        System.out.println(ldt.getDayOfYear());

        //获取小时
        System.out.println(ldt.getHour());
        System.out.println(ldt.getMinute());

        System.out.println(ldt.getSecond());

        //计算2021/11/11 是星期几
        //计算2021/11/11 15:32:31在这一年中经历了多少月，
        // 多少天，多少小时，多少分钟，多少秒

    }

}
